{% extends 'base.twig' %}

{% block breadcrumb %}
	<ol class="breadcrumb">
		<li>Личный кабинет</li>
		<li class="active">Настройки</li>
	</ol>
{% endblock %}

{% block head %}
	<script type="text/javascript">
		$(function () {
			$('#userSettings').ajaxForm({
				dataType: 'json',
				beforeSubmit: function () {
					if ($('#inputNewPassword').val() != $('#inputNewRepeatPassword').val()) {
						$('#inputNewRepeatPassword').css('background-color', '#ffcccc');
					} else {
						$('#inputNewRepeatPassword').css('background-color', '');
					}
					$.fancybox.showLoading();
				},
				success: function (d) {
					$.fancybox.hideLoading();
					if (d['error'] == 'invalid_password') {
						$('#userSettings .text-danger').html('Неправильный пароль!');
					}
					if (d['error'] == 'password_not_equal') {
						$('#userSettings .text-danger').html('Пароли не совпадают!');
					}

					location.reload();
				}
			})
		});
	</script>
{% endblock %}

{% block content %}
	<form action="/user/settings/" method="post" role="form" class="form-horizontal" id="userSettings">
		<div class="panel panel-default">
			<div class="panel-body">
				<button type="submit" class="btn btn-primary">Применить</button>
				<button type="reset" class="btn btn-danger">Сбросить</button>
			</div>
		</div>

		<div class="text-danger"></div>
		<div class="form-group">
			<label for="inputName" class="col-sm-2 control-label">ФИО:</label>

			<div class="col-sm-10">
				<input name="info[name]" class="form-control" id="inputName" placeholder="Иванов Иван Ивановия" value="{{ _settings.name }}">
			</div>
		</div>
		<div class="form-group">
			<label for="inputPhone" class="col-sm-2 control-label">Телефон:</label>

			<div class="col-sm-10">
				<input name="info[phone]" class="form-control" id="inputPhone" placeholder="8121234567" value="{{ _settings.phone }}">
			</div>
		</div>
		<div class="form-group">
			<label for="inputEmail" class="col-sm-2 control-label">E-mail:</label>

			<div class="col-sm-10">
				<input name="info[email]" class="form-control" id="inputEmail" placeholder="ivanov@site.ru" value="{{ _settings.email }}">
			</div>
		</div>
		<div class="form-group">
			<label for="inputAddress" class="col-sm-4 control-label">Адрес:</label>

			<div class="col-sm-8">
				<input name="info[address]" class="form-control" id="inputAddress" placeholder="г. Санкт-Петербург, Невский пр., д. 101" value="{{ _settings.address }}">
			</div>
		</div>
		<hr>
		<div class="form-group">
			<label for="inputNewPassword" class="col-sm-2 control-label">Новый пароль:</label>

			<div class="col-sm-10">
				<input name="info[new_password]" class="form-control" id="inputNewPassword" type="password">
			</div>
		</div>

		<div class="form-group">
			<label for="inputNewRepeatPassword" class="col-sm-2 control-label">еще раз:</label>

			<div class="col-sm-10">
				<input name="info[repeat_password]" class="form-control" id="inputNewRepeatPassword" type="password">
			</div>
		</div>
		<hr>
		<div class="form-group">
			<label for="inputPassword" class="col-sm-2 control-label">Пароль:</label>

			<div class="col-sm-10">
				<input name="info[password]" class="form-control" id="inputPassword" type="password">
			</div>
		</div>
	</form>
{% endblock %}
